package com.qyhl.webtv.module_broke.scoop.attention;


import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.circle.ScoopListBean;
import com.qyhl.webtv.module_broke.common.BrokeUrl;

import java.util.List;

/**
 * Created by qyhl on 2017/12/13.
 */

public class ScoopMyAttentionModel implements ScoopMyAttentionContract.ScoopMyAttentionModel {
    private ScoopMyAttentionPresenter mPresenter;

    public ScoopMyAttentionModel(ScoopMyAttentionPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    /**
     * 获取我关注的内容
     *
     * @param brokeId
     */
    @Override
    public void getAttention(final String brokeId) {
        String userName = CommonUtils.getInstance().getUserName();

        EasyHttp.get(BrokeUrl.GET_MY_ATTENTION)
                .params("username", userName)
                .params("brokeId", brokeId)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .execute(new SimpleCallBack<List<ScoopListBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            if ("0".equals(brokeId)) {
                                mPresenter.setError(2, "您还没有关注任何内容！");
                            } else {
                                mPresenter.setError(3, "no more");
                            }
                        } else {
                            if ("0".equals(brokeId)) {
                                mPresenter.setError(4, "解析出错，加载失败！");
                            } else {
                                mPresenter.setError(5, "解析出错，加载失败！");
                            }
                        }

                    }

                    @Override
                    public void onSuccess(List<ScoopListBean> scoopListBeans) {
                        if (scoopListBeans != null && scoopListBeans.size() > 0) {
                            if ("0".equals(brokeId)) {
                                mPresenter.setData(scoopListBeans, false);
                            } else {
                                mPresenter.setData(scoopListBeans, true);
                            }
                        } else {
                            if ("0".equals(brokeId)) {
                                mPresenter.setError(2, "您还没有关注任何内容！");
                            } else {
                                mPresenter.setError(3, "no more");
                            }
                        }
                    }
                });

    }
}
